package com.example.xyxwebbackend001.controller;


import com.example.xyxwebbackend001.common.CommonResult;
import com.example.xyxwebbackend001.config.FileUploadConfig;
import com.example.xyxwebbackend001.model.DTO.*;
import com.example.xyxwebbackend001.model.entity.CPosts;
import com.example.xyxwebbackend001.model.entity.ContentBlock;
import com.example.xyxwebbackend001.model.vo.ArticlePathListVO;
import com.example.xyxwebbackend001.service.CPostsService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

@RestController
@RequestMapping("/cult-pop")
public class CultPopController {
    @Autowired
    private CPostsService cPostsService;

    @Autowired
    private FileUploadConfig fileUploadConfig;

    //    获取文章详情
    @GetMapping("/{cultId}")
    public CommonResult<Object> getCPostDetail(@PathVariable Integer cultId) {
        try {
            CPosts res = cPostsService.getPostDetail(cultId);

            if (res != null) {
                return CommonResult.message(res);
            }
            return CommonResult.fail(200, "执行成功！");

        } catch (Exception e) {
            return CommonResult.error("系统异常：" + e.getMessage());
        }
    }

    //    根据城市查询文章列表
    @GetMapping("/list")
    public CommonResult<List<ArticleSimpleDTO>> getArticlesByCity(
            @RequestParam("cityCode") String cityId) {
        return CommonResult.message(cPostsService.getArticlesByCity(cityId));
    }

    //    获取文章详情
    @GetMapping("/articles/detail")
    public CommonResult<Map<String, Object>> getCPostDetailById(@RequestParam("id") Integer id) {
        return CommonResult.message(cPostsService.getArticleDetail(id));
    }

    @GetMapping("/articles/path")
    public CommonResult<List<ArticlePathListVO>> getArticlePathList(@RequestParam("tags") String tags) {
        return CommonResult.message(cPostsService.getArticlePathList(tags));
    }
}
